When there is no change in file text for program, no need to update program#51626
Merged
Conversation
… to determine the version instead of delaying so that new program is not created if file contents have not changed
jakebailey
reviewed
Nov 22, 2022
jakebailey
left a comment
Member
There was a problem hiding this comment.
Seems good to me, good baseline improvement. I am confused about readFile though.
| const compilerHost: CompilerHost = { | ||
| getSourceFile: createGetSourceFile( | ||
| (fileName, encoding) => host.readFile(fileName, encoding), | ||
| (fileName, encoding) => !encoding ? compilerHost.readFile(fileName) : host.readFile(fileName, encoding), |
Member
There was a problem hiding this comment.
Odd to me that this looks like this, given compilerHost just defers to host.readFile too. Is it expected that CompilerHost is missing this parameter?
Member
Author
There was a problem hiding this comment.
I think we are suppose to deprecate the encoding = charSet from compilerOptions Our APIs dont have that consistent everywhere.
Member
Author
There was a problem hiding this comment.
compilerHost.readFile is normally used for module resolution only and it doesnt support passing encoding...
andrewbranch
approved these changes
Nov 29, 2022
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There have been cases where file change notification is reported twice by the native node file system events. We have setup many optimizations for this. eg we schedule updates instead of updating right away so if the events occur before that scheduled update, the program gets updated only once. But if the repeat event is received after we have updated event, we recreate program where the structure is used completely but we still have new copy. This means we don't emit program but there is still cost incurrent with binding and creating type checker and more over user gets notified that file change was detected and program will be rebuilt. So, from user perspective we are doing double compilation even though we didn't really emit anything. The main root cause for creating new program is that when getting new source file version, we don't read text and figure out if it has changed or not. We used to delay it to creating source files.
With this change, we will read file if the sourceFile state is unknown (that is we received the file change event). So, if text has not changed, we won't create new program, not report file change detected either.
Also had to modify how we read file for the sourceFile so that we can use cached text because now there are two places where we are reading source file text.
Fixes #51611